<template>
  <div class="careerOverviewWrapper">
    <div class="mainContent">
      <div v-for="item,index in secondLayerList" :key="index">
        <generalTextComponent :scrollFirstIndex="scrollFirstIndex" :layerList="secondLayerList" :layerItem="item"
          :topId="topId" :isAdmin="isAdmin" :aiCreateStatus.sync="aiCreateStatus" :isSuperToken="isSuperToken"
          :editAll="editAll" />
      </div>
    </div>
    <rightsideScroller :secondLayerList="secondLayerList" :workEnviromentIndex="workEnviromentIndex" />
  </div>
</template>

<script>
import { homepageLayerData } from "@/api/position-detail";
import generalTextComponent from "../generalTextComponent";
import rightsideScroller from "../components/rightsideScroller.vue";
export default {
  name: "generalLayerComponet",
  components: {
    generalTextComponent,
    rightsideScroller,
  },
  props: {
    allLayerList: {
      type: Array,
      default: () => [],
    },
    currentTab: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      topId: "",
      secondLayerList: [],
      secondLayerIds: [],
      isSuperToken: false,
      aiCreateStatus: false,
      isAdmin: true, //上线的时候要改掉啊啊啊啊
      editAll: false,
      workEnviromentIndex: 1, //用来右侧滚动栏用的
    };
  },
  methods: {
    reqHomepageLayerData() {
      const params = {
        layerIds: this.secondLayerIds.join("_"),
        id: this.$route.query.id,
        topId: this.topId,
      };
      homepageLayerData(params)
        .then((res) => {
          if (res.code == 200) {
            this.secondLayerList = res.data;
          }
        })
        .catch((err) => {
          //console.log("err", err);
          this.$message.error("服务器开小差啦");
        })
        .finally(() => {
          this.loading = false;
        });
    },
  },
  watch: {
    allLayerList: {
      handler(newValue, oldValue) {
        // //console.log("allLayerList newValue，你为嘛不触发？？", newValue);
        if (newValue.length) {
          newValue.forEach((item, index) => {
            if (item.layerId == this.currentTab) {
              this.scrollFirstIndex = index;
              this.topId = item.layerId;
              this.secondLayerIds = item.children.map((_item, _index) => {
                if (_item.layerId == 8) {
                  this.workEnviromentIndex = _index;
                }
                return _item.layerId;
              });
              this.reqHomepageLayerData();
            }
          });
        }
      },
      immediate: true,
      deep: true,
    },
  },
  mounted() {
    this.isSuperToken =
      localStorage.getItem("superToken") ==
        "407404EAEC845F1B91A104B80FE86D89" ||
      localStorage.getItem("superToken") == "5FD271D8A0AA315DD218801C0C3A0DEA";
    if (
      this.$route.query.superToken == "407404EAEC845F1B91A104B80FE86D89" ||
      this.$route.query.superToken == "5FD271D8A0AA315DD218801C0C3A0DEA"
    ) {
      this.specialHidden = false;
    }
  },
};
</script>

<style lang="scss" scoped>
.careerOverviewWrapper {
  display: flex;
  position: relative;
  box-shadow: inset 4px 4px 11px 2px rgba(118, 170, 244, 0.18);
  border: 1px solid #eaedf7;
  padding: 14px;
  flex: 1;
  max-height: calc(100vh - 160px);
  overflow-y: scroll;
  .mainContent {
    flex: 1;
  }
}
</style>